﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;

public partial class Stat_DayStat : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            StatInit();
            BIND();
        }
    }

    private void StatInit()
    {
        StatChartlet.Visible = false;
        txtYears.Text = DateTime.Now.Year.ToString();
        txtMonths.Text = DateTime.Now.Month.ToString();
        txtDays.Text = DateTime.Now.Day.ToString();
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        BIND();
    }

    private void BIND()
    {
        StatChartlet.Visible = true;
        Usas.BLL.Cms.StatOperate so = new Usas.BLL.Cms.StatOperate();
        ArrayList XTitle = new ArrayList();

        ArrayList[] ChartData = new ArrayList[1];
        ChartData[0] = new ArrayList();

        string years = txtYears.Text.Trim().Length > 0 ? " and years=" + txtYears.Text.Trim() : "";
        string months = txtMonths.Text.Trim().Length > 0 ? " and months=" + txtMonths.Text.Trim() : "";
        string days = txtDays.Text.Trim().Length > 0 ? " and days=" + txtDays.Text.Trim() : "";

        DataSet ds = so.DayStat(years, months, days);

        if (ds != null && ds.Tables[0].Columns.Count > 0)
        {
            for (int i = 0; i < ds.Tables[0].Columns.Count; i++)
            {
                //string name = ds.Tables[0].Columns[i].Caption;
                XTitle.Add(i +  "时");
                object b = ds.Tables[0].Rows[0][i] == null || ds.Tables[0].Rows[0][i].ToString() == "0" || ds.Tables[0].Rows[0][i].ToString() == "" ? "0" : ds.Tables[0].Rows[0][i].ToString();
                ChartData[0].Add(b.ToString());
            }
        }
        StatChartlet.ChartTitle.Text = (txtYears.Text.Trim().Length > 0 ? txtYears.Text.Trim() + "年": "")
            + (txtMonths.Text.Trim().Length > 0 ? txtMonths.Text.Trim() + "月": "")
            + (txtDays.Text.Trim().Length > 0 ? txtDays.Text.Trim() + "日": "")
            + "时段流量分析";
        StatChartlet.YLabels.UnitText = "流量";
        StatChartlet.XLabels.UnitText = "时间";

        StatChartlet.InitializeData(ChartData, XTitle, null);

        object obj = so.hourStat(" 1=1 " + years + months + days);
        nct.Text = Convert.DBNull != obj ? obj.ToString() : "0";
        obj = so.hourStat(" 1=1 ");
        act.Text = Convert.DBNull != obj ? obj.ToString() : "0";

   
    }
}
